import 'dart:io';

import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:app/src/config/app_data_config.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/http/bean/banner.dart';
import 'package:app/src/http/bean/http_data.dart';
import 'package:app/src/http/bean/user.dart';
import 'package:app/src/http/sign.dart';
import 'package:app/src/http/url.dart';
import 'package:app/src/manager/user_manager.dart';
import 'package:app/src/ui/dialog/dailog.dart';

///广告位
class BannerModel {
  ///pageView首页的通知栏
  static void getcompanynotice(
      BuildContext context,
      bool isEnableLoad,
      ResponseCallbackWithT<AppHttpResult<List<CompanyNoticeInfo>?, CompanyNoticeInfo?>>
          callback) {
    var url = Url.baseurl() + Url.getcompanynotice;
    var queryParameters = Map<String, dynamic>();
    var token = AppDataConfig.getToken();
    var subData = SubData();
    subData.commondata = CommonData();
    queryParameters['data'] = subData.jsonEncodeToJson();
    var sign = getSign(queryParameters);
    queryParameters['sign'] = sign;
    //print('签名：$sign');
    KOhttp(url)
      ..isEnableLoad(isEnableLoad, context)
      // ..onStart(() {
      //   print('开始');
      // })
      ..onError((code, error) {
        // print('错误:\t$code\t$error');
        AppDialog.showDialogWithError(context, code, error);
      })
      ..onSuccess((result) {
        //print('============================通知栏信息:\n$result');
        // PrintUtils.printlnLong('============================通知栏信息:\n$result');
        //fixme 注意：公告管理这里，图片返回的格式如下：（图片字段为：NoticePicture）
        //fixme 单张图片：http://test.bwg2017.com/["/UploadFile/Notice/220901637976225938645625.png"]
        //fixme 多张图片：http://test.bwg2017.com/[\"/UploadFile/Notice/220513637880281547492969.jpg\",\"/UploadFile/Notice/220513637880281547698047.jpg\",\"/UploadFile/Notice/220513637880281615266407.jpg\"]"
      })
      // ..onFinish(() {
      //   print('结束');
      // })
      ..isCache(false)
      ..addHeader('token', token)
      ..addFormDatas(queryParameters)
      ..isAllowedRepeat = false //是否允许重复请求
      ..isUpdateCallback = true //实时更新回调函数
      ..contentType = ContentType.form
      ..isEnableLog = AppDataConfig.isEnableLog
      ..postASync<AppHttpResult<List<CompanyNoticeInfo>?, CompanyNoticeInfo?>>(
              AppHttpResult()
                ..Data = <CompanyNoticeInfo>[]
                ..t2 = CompanyNoticeInfo())
          ?.then((result) {
        //print("请求结果：=======================================");
        callback?.call(result);
      });
  }
}
